<?php
	function alertMonth2($text,$color,$icon,$day)
	{
		$colors = array
		(
			'red'=>'#ff0000',
			'yellow'=>'#FFFB00',
			'green'=>'#00ff00',
		);
		$icons = array
		(
			'family'=>'images/family_super_small.png',
			'business'=>'images/briefcase_super_small.png',
			'pleasure'=>'images/coffee_super_small.png',
		);
		return 
		'<VBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle" backgroundColor="'.$colors[$color].'" backgroundAlpha="0.3" cornerRadius="2" click="dispatchEvent(viewstack1, \'eventpreview\')">
			<Text text="'.$day.':"/>
			<Text text="'.$text.'"/>
			<Image source="'.$icons[$icon].'" width="20" height="20" />
		</VBox>';
	}
	function checkMonthAlert2($day)
	{
		$events = array
		(
			5=>array('Important Meeting','red','business'),
			7=>array('Parrent`s Meeting','yellow','family'),
			8=>array('Family Union','yellow','family'),
			13=>array('Fatal day','red','pleasure'),
			16=>array('Travel to Sofia','green','business'),
			18=>array('Go to Heavy Metal Concert','red','pleasure'),
			23=>array('Team Building','green','business'),
			27=>array('Go to SPA','yellow','pleasure')
		);
		#$events = array();
		if(isset($events[$day]))
		{
			return alertMonth2
			(
				$events[$day][0],
				$events[$day][1],
				$events[$day][2],
				$day
			);
		}
		return '<Text text="'.$day.'"/>';
	}

?>
<Canvas label="Month view" width="100%" height="100%">
	<VBox width="100%" height="100%" verticalAlign="middle">
		<HBox width="100%" horizontalAlign="center">
			<HBox width="4%" height="100"></HBox>
			<?php
				$marker = 0;
				for($i=1;$i<=date('N',strtotime('01-'.(date('m')).'-'.date('Y')));$i++)
				{
					?><HBox width="13%" height="100" borderStyle="solid" border="1"  cornerRadius="5" backgroundAlpha="0.8" verticalAlign="top" horizontalAlign="left" backgroundColor="#b0b0b0"></HBox><?php
					$marker++;
				}
				for($i=1;$i<=date('t');$i++,$marker++)
				{
					if($marker % 7 == 0)
					{
						?></HBox><HBox width="100%" verticalAlign="middle" horizontalAlign="right">
						<HBox width="4%" height="100"></HBox><?php
					}
					if($marker % 7 == 0 || $marker % 7 == 6)
					{
						?><HBox width="13%" height="100" borderStyle="solid" cornerRadius="5" border="1" backgroundAlpha="0.8" verticalAlign="top" horizontalAlign="left" backgroundColor="#d0d0d0"><?php echo checkMonthAlert2($i); ?></HBox><?php
					}
					else
					{
						?><HBox width="13%" height="100" borderStyle="solid" cornerRadius="5" border="1" backgroundAlpha="0.8" verticalAlign="top" horizontalAlign="left" backgroundColor="#f0f0f0"><?php echo checkMonthAlert2($i); ?></HBox><?php
					}
				}
				for($i=$marker % 7;$i<7;$i++)
				{
					?><HBox width="13%" height="100" borderStyle="solid"  cornerRadius="5" border="1" backgroundAlpha="0.8" verticalAlign="top" horizontalAlign="left" backgroundColor="#b0b0b0"></HBox><?php
				}
			?>
		</HBox>
	</VBox>
</Canvas>